export default{
	
	// 间隔时间
	spaceTime:function(old,now){
			old = new Date(old);
			now = new Date(now);
			var told = old.getTime();
			var tnow = now.getTime();
			if(told > (tnow + 1000*60*5)){
				return now;
			}else{
				return '';
			}
			
	},
	
	// 聊天时间
	msgDateTime:function(e){
		let old = new Date(e);
		let now = new Date();
		// 获取old具体时间
		let d = old.getTime();
		let h = old.getHours();
		let m = old.getMinutes();
		let Y = old.getFullYear();
		let M = old.getMonth() + 1;
		let D = old.getDate();
		
		// 获取now具体时间
		let nd = now.getTime();
		let nh = now.getHours();
		let nm = now.getMinutes();
		let nY = now.getFullYear();
		let nM = now.getMonth() + 1;
		let nD = now.getDate();
		
		// 当天时间
		if(D === nD && M === nM && Y === nY){
			if(h < 10){
				h = '0' + h
			}
			if(m < 10){
				m = '0' + m
			}
			return h + ':' + m;
		}
		
		// 昨天
		if(D+1 === nD && M === nM && Y === nY){
			if(h < 10){
				h = '0' + h
			}
			if(m < 10){
				m = '0' + m
			}
			return '昨天' + h + ':' + m;
		}else if(Y === nY ){
			if(h < 10){
				h = '0' + h
			}
			if(m < 10){
				m = '0' + m
			}
			// 今年
			return M + '月' + D + '日' + h + ':' + m;
		}else{
			if(h < 10){
				h = '0' + h
			}
			if(m < 10){
				m = '0' + m
			}
			// 今年
			return Y + '年' +M + '月' + D + '日' + h + ':' + m;
		}
	},
	
	// 日期转化
	dateTime(e){
		let old = new Date(e);
		let now = new Date();
		// 获取old具体时间
		let d = old.getTime();
		let h = old.getHours();
		let m = old.getMinutes();
		let Y = old.getFullYear();
		let M = old.getMonth();
		let D = old.getDate();
		
		// 获取now具体时间
		let nd = old.getTime();
		let nh = old.getHours();
		let nm = old.getMinutes();
		let nY = old.getFullYear();
		let nM = old.getMonth();
		let nD = old.getDate();
		
		// 当天时间
		if(D === nD && M === nM && Y === nY){
			if(h < 10){
				h = '0' + h;
			}
			if(m < 10){
				m = '0' + m;
			}
			return h + ':' + m
		}
		
		// 昨天
		if(D+1 === nD && M === nM && Y === nY){
			if(h < 10){
				h = '0' + h;
			}
			if(m < 10){
				m = '0' + m;
			}
			return '昨天' + h + ':' + m
		}else{
			// 大于两天
			return Y + '-' + M + '-' + D
		}
	}
}